package cn.changeforyou.web.dao.mybatis.ext.accessScene;

import cn.changeforyou.web.dao.mybatis.ext.metaInfo.MappedStatementMetaInfo;
import cn.changeforyou.web.dao.mybatis.ext.metaInfo.parser.MappedStatementMetaInfoHolder;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.builder.annotation.ProviderContext;


/**
 * @author zhyu
 * @version 1.0
 * @date 2022/2/9 20:59
 */
@Slf4j
public class SqlProvider {

    /**
     * 生成根据主键获取单个实体类的sql
     *
     * @param providerContext
     * @param param
     * @return
     */
    public String dynamic(ProviderContext providerContext, Object param) {
        MappedStatementMetaInfo mappedStatementMetaInfo = MappedStatementMetaInfoHolder.getOrCreateMappedStatementMetaInfoInProvider(providerContext, param);
        String sql = mappedStatementMetaInfo.getSql();
        if (log.isDebugEnabled()) {
            log.debug("provider 提供的mybatis sql是: \n{}", sql);
        }
        return sql;
    }
}
